<Window x:Class="ICSharpCode.Data.Core.UI.Windows.ConnectionWizardWindow"
    x:Name="This"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:data="http://icsharpcode.net/data"
    xmlns:userControls="clr-namespace:ICSharpCode.Data.Core.UI.UserControls"
    Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"
    Title="Add new database connection" Height="400" Width="600" WindowStartupLocation="CenterOwner">
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../Images/ImageDictionary.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>

    <Grid Margin="5">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" /> 
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>

        <Border Background="White">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>

                <Image Margin="5,5,10,10" Width="16" Height="16" Source="{StaticResource DatabaseConnectImage}" VerticalAlignment="Center" />
                <TextBlock Grid.Column="1" Margin="10,5,10,10" FontWeight="Bold" VerticalAlignment="Center">Add new database connection</TextBlock>
            </Grid>
        </Border>

        <TextBlock Grid.Row="1" Margin="3">Database driver:</TextBlock>
        <ComboBox x:Name="cboDatabaseDriver" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" Margin="3" SelectedItem="{Binding SelectedDatabaseDriver, ElementName=This}" 
            ItemsSource="{x:Static data:DatabaseDriver.DatabaseDrivers}">
            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Name}" />
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>
        
        <TextBlock Grid.Row="2" Margin="3">Data source:</TextBlock>
        <Grid Grid.Row="2" Grid.Column="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            
            <ComboBox x:Name="cboDatasources" Margin="3" IsEditable="True" KeyDown="cboDatasources_KeyDown" 
                SelectedItem="{Binding SelectedDatasource, ElementName=This}" ItemsSource="{Binding SelectedDatabaseDriver.Datasources, ElementName=This}">
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Name}" />
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>
            <Button Grid.Column="1" Margin="3" Content="Auto Discover" Click="btnAutoDiscover_Click" />
        </Grid>
        
        <ContentControl Grid.Row="3" Grid.Column="1" Margin="3" Content="{Binding SelectedDatasource.ControlPanel, ElementName=This}" />
        
        <Button x:Name="btnConnect" Grid.Row="4" Grid.Column="1" Margin="3" Content="Connect" HorizontalAlignment="Right" Click="btnConnect_Click" />
        
        <TextBlock Grid.Row="5" Margin="3">Database:</TextBlock>

        <ComboBox x:Name="cboDatabases" Grid.Row="5" Grid.Column="1" Margin="3" SelectedItem="{Binding SelectedDatabase, ElementName=This}" 
            ItemsSource="{Binding SelectedDatasource.Databases, ElementName=This}" SelectionChanged="cboDatabases_SelectionChanged">
            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Name}" />
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>
        
        <Expander Grid.Row="6" Grid.Column="1" Margin="2" Header="Connection String" VerticalAlignment="Top"
            IsExpanded="{Binding SelectedDatasource.UseUserDefinedConnectionString, ElementName=This}">
            <TextBox Text="{Binding SelectedDatasource.UserDefinedConnectionString, ElementName=This}" MinLines="5" />
        </Expander>
        
        <userControls:LoadingCircle Grid.Row="7" Margin="3" IsActivated="{Binding IsLoading, ElementName=This}" />
        <StackPanel Grid.Row="7" Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right">
            <Button x:Name="btnAdd" Margin="3" Padding="3" Click="btnAdd_Click" IsEnabled="False">Add</Button>
            <Button Margin="3" IsCancel="True" Padding="3" Click="btnCancel_Click">Cancel</Button>
        </StackPanel>
    </Grid>
</Window>